// pages/patient/add/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    items: [
      {value: '1', name: '是'},
      {value: '2', name: '否', checked: 'true'}
    ],
    itemss: [
      {value: '1', name: '男'},
      {value: '2', name: '女', checked: 'true'}
    ],
    peopleList:['父子','兄妹','配偶','朋友','亲戚','其他'],
    relationshipName:'请选择与就诊人的关系',
    relationship:'',
    is_adult:'2',
    patient_name:'',
    sex:'2',
    patient_mobile:'',
    patient_card:'',
    type:''
  },
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)

    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }

    this.setData({
      items
    })

    this.setData({
      is_adult:e.detail.value
    })
  },

  radioChange1(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)

    const itemss = this.data.itemss
    for (let i = 0, len = itemss.length; i < len; ++i) {
      itemss[i].checked = itemss[i].value === e.detail.value
    }

    this.setData({
      itemss
    })

    this.setData({
      sex:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    this.setData({
      type:options.type,
      k_name:options.name?options.name:'',
      goods_id:options.goods_id?options.goods_id:'',
      patient_id:options.patient_id?options.patient_id:'',
      patient_name:options.patient_name?options.patient_name:'',
      department_id:options.department_id?options.department_id:'',
      mail_address_id:options.mail_address_id?options.mail_address_id:'',
      address:options.address?options.address:'',
    })
    
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  changePeople(){
    let app=this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function(res) {
      console.log(res.tapIndex)
      let relationshipName=''
      if(res.tapIndex==0){
        relationshipName='父子'
      }else if(res.tapIndex==1){
        relationshipName='兄妹'
      }else if(res.tapIndex==2){
        relationshipName='配偶'
      }else if(res.tapIndex==3){
        relationshipName='朋友'
      }else if(res.tapIndex==4){
        relationshipName='亲戚'
      }else{
        relationshipName='其他'
      }
      app.setData({
        relationship:(res.tapIndex)+1,
        relationshipName:relationshipName
      })
      },
      fail: function(res) {
      console.log(res.errMsg)
      }
      })
  },

  addBtn(){

    let _this = this;
    App._get('patient/add', {
      is_adult:_this.data.is_adult,
      patient_name:_this.data.patient_name,
      sex:_this.data.sex,
      patient_mobile:_this.data.patient_mobile,
      patient_card:_this.data.patient_card,	
      relationship:_this.data.relationship
    }, result => {
      // 设置顶部导航栏栏
      // _this.setPageBar(result.data.page);
      // _this.setData({
      //   tabList:result.data.list
      // });
      wx.redirectTo({
        url: '/pages/patient/index?type='+this.data.type+'&name='+this.data.k_name+'&goods_id='+this.data.goods_id+'&department_id='+this.data.department_id+'&mail_address_id='+this.data.mail_address_id+'&address='+this.data.address,
      })
      // 回调函数
    });
    console.log(this.data)
  },
  bindHideName(e){
    this.setData({
      patient_name:e.detail.value
    })
  },
  bindHidePhone(e){
    this.setData({
      patient_mobile:e.detail.value
    })
  },
  bindHideCard(e){
    this.setData({
      patient_card:e.detail.value
    })
  },
})